﻿#-*- coding:utf-8 -*-

from flask import Flask,request,render_template
import pymysql
app = Flask(__name__)


@app.route('/')
def index():
	return render_template('index.html')

@app.route('/search',methods=['GET', 'POST'])
def search():
	db= pymysql.connect(host="127.0.0.1",user="root",  
		password="root",db="db",port=3306,charset='utf8')
	# 使用cursor()方法获取操作游标  
	cur = db.cursor() 

	keyword = request.args.get('kw')
	count = request.args.get('count')
	sql = "select * from images where name like '%{}%'".format(keyword)
	cur.execute(sql)
	data = cur.fetchmany(int(count))
	print(keyword)
	return render_template('index.html',images = data)

if __name__ == '__main__':
	app.run(debug=True)
	